/**
 * Desenvolvido pela Fábrica de Software do CESUPA.
 * Todos os direitos reservados.
 */
package br.cesupa.fabsoft.nomedoprojeto.system.application.facades;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;

/**
 * Manage validation messages used by the Java Server Faces framework.
 *
 * @author Breno Leite
 */
public class FacesMessageFacade {

    private Severity severity;
    private String message;
    private String details;
    private String componentId;

    /**
     * Shows an information message for a given UI component.
     *
     * @param componentId the target componenent which the message should be
     * attached to
     * @param message the message to be displayed
     * @return an interface used to define translation aspects
     */
    public FacesMessageTranslationContext displayInformationMessage(
            final String componentId, final String message) {
        this.componentId = componentId;
        this.message = message;
        this.severity = FacesMessage.SEVERITY_INFO;
        return new FacesMessageTranslationContext(this);
    }

    /**
     * Shows an information message at the view with no related UI component.
     *
     * @param message the message to be displayed
     * @return an interface used to define translation aspects
     */
    public FacesMessageTranslationContext displayInformationMessage(
            final String message) {
        this.message = message;
        this.severity = FacesMessage.SEVERITY_INFO;
        return new FacesMessageTranslationContext(this);
    }

    /**
     * Shows a warning message for a given UI component.
     *
     * @param componentId the target componenent which the message should be
     * attached to
     * @param message the message to be displayed
     * @return an interface used to define translation aspects
     */
    public FacesMessageTranslationContext displayWarningMessage(
            final String componentId, final String message) {
        this.componentId = componentId;
        this.message = message;
        this.severity = FacesMessage.SEVERITY_WARN;
        return new FacesMessageTranslationContext(this);
    }

    /**
     * Shows a warning message at the view with no related UI component.
     *
     * @param message the message to be displayed
     * @return an interface used to define translation aspects
     */
    public FacesMessageTranslationContext displayWarningMessage(
            final String message) {
        this.message = message;
        this.severity = FacesMessage.SEVERITY_WARN;
        return new FacesMessageTranslationContext(this);
    }

    /**
     * Shows an error message for a given UI component.
     *
     * @param componentId the target componenent which the message should be
     * attached to
     * @param message the message to be displayed
     * @return an interface used to define translation aspects
     */
    public FacesMessageTranslationContext displayErrorMessage(
            final String componentId, final String message) {
        this.componentId = componentId;
        this.message = message;
        this.severity = FacesMessage.SEVERITY_ERROR;
        return new FacesMessageTranslationContext(this);
    }

    /**
     * Shows an error message at the view with no related UI component.
     *
     * @param message the message to be displayed
     * @return an interface used to define translation aspects
     */
    public FacesMessageTranslationContext displayErrorMessage(
            final String message) {
        this.message = message;
        this.severity = FacesMessage.SEVERITY_ERROR;
        return new FacesMessageTranslationContext(this);
    }

    /**
     * Shows an error message for a given UI component.
     *
     * @param componentId the target componenent which the message should be
     * attached to
     * @param message the message to be displayed
     * @return an interface used to define translation aspects
     */
    public FacesMessageTranslationContext displayFatalMessage(
            final String componentId, final String message) {
        this.componentId = componentId;
        this.message = message;
        this.severity = FacesMessage.SEVERITY_FATAL;
        return new FacesMessageTranslationContext(this);
    }

    /**
     * Shows a fatal message at the view with no related UI component.
     *
     * @param message the message to be displayed
     * @return an interface used to define translation aspects
     */
    public FacesMessageTranslationContext displayFatalMessage(
            final String message) {
        this.message = message;
        this.severity = FacesMessage.SEVERITY_FATAL;
        return new FacesMessageTranslationContext(this);
    }

    /**
     * @return the defined severity
     */
    public Severity getSeverity() {
        return severity;
    }

    /**
     * @return the defined message
     */
    public String getMessage() {
        return message;
    }

    /**
     * @return the defined details
     */
    public String getDetails() {
        return details;
    }

    /**
     * @return the defined componentId
     */
    public String getComponentId() {
        return componentId;
    }
}
